<?php

session_start();
if(!array_key_exists("user", $_SESSION) || $_SESSION['account'] != 2){
	header("Location: ../common/redirect.php");
	exit;
}

include_once("../class/db.php");
$db = new db();
$sql = "SELECT name, link FROM course WHERE creator = '{$_SESSION['user']}'";
$course = $db->execute($sql, "all");
$counter = 0;
$options = "";
if($course != false){
	foreach($course as $row){
		$sql = "SELECT id, title FROM course_modules WHERE link = '{$row['link']}'";
		$course_modules = $db->execute($sql, "all");
		if($course_modules == false){
			continue;
		} else {
			$options .= '<OPTGROUP LABEL="'.$row['name'].'">';
			foreach($course_modules as $modules){
				$options .= '<option value="'.$modules['id'].'">'.$modules['title'].'</option>';
				$counter++;
			}
			$options .= '</OPTGROUP>';
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PIE EDUCATION | Educational Network</title>
<link rel="stylesheet" type="text/css" href="/css/style-student.css" />
<script type="text/javascript" src="/js/index.js"></script>
<script language="JavaScript" src="/js/ts_picker.js"></script>
<script language="Javascript1.2">
<!--
setTimeout('location.href="/logout.php?expire=1"',600000);
// -->
</script>
<script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-35230372-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>

<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#000000"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td width="350" height="30">&nbsp;</td>
        <td align="right" valign="bottom"><a href="class.php" class="top-menu" style="color:#999">MY CLASS</a> <a href="schedule.php" class="top-menu" style="color:#999">CALENDAR</a> <a href="homework.php" class="top-menu" style="color:#999">HOMEWORK</a> <a href="test.php" class="top-menu" style="color:#999">EXAMS</a> <a href="grades.php" class="top-menu" style="color:#999">GRADES</a> <a href="tools.php" class="top-menu" style="color:#999">TOOLS</a> <a href="/logout.php" class="top-menu" style="color:#999">SIGN OUT</a></td>
      </tr>
	  <tr>
        <td>&nbsp;</td>
        <td align="right" valign="bottom"><a href="/profile/" class="login-menu" style="color:#FFF"><?php echo $_SESSION['name'].' '.$_SESSION['lname']; ?></a> <a href="/common/redirect.php" class="login-menu" style="color:#FFF">My Documents</a> <a href="/network/" class="login-menu" style="color:#FFF">My Wall</a> <a href="/common/settings.php" class="login-menu" style="color:#FFF">Settings</a></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td height="30" style="background-image:url(/images/top-bg-student.png); background-repeat:repeat-x">&nbsp;</td>
  </tr>
  <tr>
    <td height="550" align="center" valign="top"><table width="980" border="0" cellspacing="4" cellpadding="4">
	  <?php
	  if($course != false && $counter != 0){
	  ?>
      <tr>
        <td><img src="../images/create-homework.png" width="350" height="50" alt="Create Homework" /></td>
      </tr>
      <tr>
        <td><form id="homeworkCreator" name="homeworkCreator" method="post" action="homework.php" onsubmit="return homeworkValidation();">
            <table width="980" border="0" align="center" cellpadding="4" cellspacing="4">
              <tr>
                <td colspan="2" style="font-size:14px; color:#999">To create a homework please provide the next fields below. On the description field you can include pictures, text, url or any other information may help the student. The deliver date is optional
                  <input name="contenttype" type="hidden" id="contenttype" value="homework" />
                  <input name="solo" type="hidden" id="solo" value="true" /></td>
                </tr>
              <tr>
                <td width="200" align="right"><h2>Homework Title<span style="color:#F00">*</span></h2></td>
                <td><input name="title" type="text" class="form-course" id="title" tabindex="1" /></td>
              </tr>
              <tr>
                <td align="right"><h2>Create Homework For<span style="color:#F00">*</span></h2></td>
                <td><select name="uid" class="form-course" id="uid" tabindex="2">
                	<option value="0" selected="selected">Please Select a Module</option>
                  <?php
				  	echo $options;
                  ?>
                </select></td>
              </tr>
              <tr>
                <td align="right"><h2>Description<span style="color:#F00">*</span></h2></td>
                <td><textarea name="homework_content" class="form-course" id="homework_content" style="width: 700px; height: 120px;" tabindex="3">Some Initial Content was in this textarea</textarea></td>
              </tr>
              <tr>
                <td align="right"><h2>Deliver Date<span style="color:#F00">*</span></h2></td>
                <td><input name="end_date" type="text" class="form-course" id="end_date" tabindex="4" />  <a href="javascript:show_calendar('document.homeworkCreator.end_date', document.homeworkCreator.end_date.value);"> <img src="/images/cal.gif" width="16" height="16" border="0" alt="Click Here to Pick up the timestamp" /></a></td>
              </tr>
              <tr>
                <td align="right"><h2>Deliver Method<span style="color:#F00">*</span></h2></td>
                <td><select name="deliver_method" class="form-course" id="deliver_method" tabindex="5">
                  <option value="email" selected="selected">The homework will be delivered via email ( to my email address )</option>
                  <option value="document">The homework will be delivered on a document via pie.edu (show upload form on the site)</option>
                  <option value="custom">The homework will be created on pie.edu ( show text form on the site )</option>
                  </select></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td style="color:#F00; font-family:Arial, Helvetica, sans-serif"><em>all the fields marked with * are required fields</em></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><input name="Send" type="submit" class="submit" id="Send" value="Create a New Homework" tabindex="6" /> <input type=button class="submit-center" onClick="location.href='homework.php'" value='Cancel Creation' tabindex="10" /></td>
              </tr>
            </table>
          </form></td>
      </tr>
      <?php
      } else {
	  ?>
      <tr>
        <td align="center" style="color:#999"><div style="font-family:Arial, Helvetica, sans-serif; color:#666; font-size:16px"><strong>You don't have any active course or Active Modules</strong></div>Please first create a class or modules for a class in order to be able to create a homework<br /><br /><input type=button class="submit-center" onClick="location.href='class-create.php'" value='Create a New Class' tabindex="10" /></td>
      </tr>
      <?php
	  }
	  ?>
</table></td>
      </tr>
  <tr>
    <td height="30" align="center" style=" background-image:url(../images/bottom-bg-student.png); background-repeat:repeat-x;">&nbsp;</td>
  </tr>
  <tr>
    <td height="50" align="center" bgcolor="#000000" style="color:#fff; font-family:Arial, Helvetica, sans-serif">PIE.EDU All Rights Reserved 2012<br />
      <a href="/common/privacy.php" class="bottom-menu" style="color:#999">Privacy Policy</a> | <a href="/common/terms.php" class="bottom-menu"  style="color:#999">Terms of Use</a> | <a href="/help/main.php" class="bottom-menu" style="color:#999">Help Center</a> | <a href="/common/jobs.php" class="bottom-menu" style="color:#999">Jobs</a></td>
  </tr>
    </table>
</body>
</html>